
package com.yimixian.app.ui;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yimixian.app.R;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class MessageDialogView extends FrameLayout {

    @InjectView(R.id.title_text)
    TextView mTitleText;
    @InjectView(R.id.content_text)
    TextView mContentText;
    @InjectView(R.id.button_divider)
    View mButtonDivider;
    @InjectView(R.id.cancel_text)
    TextView mCancelText;
    @InjectView(R.id.confirm_text)
    TextView mConfirmText;
    @InjectView(R.id.ll_dialog_container)
    public LinearLayout mLlDialogContainer;
    @InjectView(R.id.fl_dialog_container)
    public FrameLayout mFlDialogContainer;

    public MessageDialogView(Context context) {
        super(context);
        initPullMessageView();
    }

    public MessageDialogView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initPullMessageView();
    }

    public MessageDialogView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initPullMessageView();
    }

    private void initPullMessageView() {
        LayoutInflater.from(getContext()).inflate(R.layout.message_dialog_view, this);
        ButterKnife.inject(this);
    }

    public void bind(String title, String message, OnClickListener clickListener) {
        if (TextUtils.isEmpty(title)) {
            mTitleText.setVisibility(View.GONE);
        } else {
            mTitleText.setText(title);
            mTitleText.setVisibility(View.VISIBLE);
        }
        mTitleText.setVisibility(View.GONE);
        mContentText.setText(message);
        setOnClickListener(clickListener);
        mButtonDivider.setVisibility(GONE);
        mCancelText.setVisibility(GONE);
    }

    public void bind(String title, String message, OnClickListener confirmClickListener,
            OnClickListener cancelClickListener) {
        if (TextUtils.isEmpty(title)) {
            mTitleText.setVisibility(View.GONE);
        } else {
            mTitleText.setText(title);
            mTitleText.setVisibility(View.VISIBLE);
        }
        mTitleText.setVisibility(View.GONE);
        mContentText.setText(message);
        setOnClickListener(confirmClickListener);
        mButtonDivider.setVisibility(VISIBLE);
        mCancelText.setVisibility(VISIBLE);
        mCancelText.setOnClickListener(cancelClickListener);
    }

    public void bindConfirm(String title, String message, OnClickListener confirmClickListener,
            OnClickListener cancelClickListener) {
        if (TextUtils.isEmpty(title)) {
            mTitleText.setVisibility(View.GONE);
        } else {
            mTitleText.setText(title);
            mTitleText.setVisibility(View.VISIBLE);
        }
        mTitleText.setVisibility(View.GONE);
        mContentText.setText(message);
        mConfirmText.setOnClickListener(confirmClickListener);
        setOnClickListener(cancelClickListener);
        mButtonDivider.setVisibility(VISIBLE);
        mCancelText.setVisibility(VISIBLE);
        mCancelText.setOnClickListener(cancelClickListener);
    }

    public void bindConfirm(String title, String message, String confirmText, OnClickListener confirmClickListener,
                 String cancelText, OnClickListener cancelClickListener) {
        if (TextUtils.isEmpty(title)) {
            mTitleText.setVisibility(View.GONE);
        } else {
            mTitleText.setText(title);
            mTitleText.setVisibility(View.VISIBLE);
        }
        mContentText.setText(message);
        mConfirmText.setOnClickListener(confirmClickListener);
        mConfirmText.setText(confirmText);
        setOnClickListener(cancelClickListener);
        mButtonDivider.setVisibility(VISIBLE);
        mCancelText.setVisibility(VISIBLE);
        mCancelText.setOnClickListener(cancelClickListener);
        mCancelText.setText(cancelText);
    }
}
